//
//  EPViewController.m
//  Epweike_Witkey
//
//  Created by Mac on 15/7/29.
//  Copyright (c) 2015年 zengxusheng. All rights reserved.
//

#import "EPViewController.h"
#import "UINavigationBar+Addition.h"
#import "NavigationView.h"

/*
 *  自定义的基控制器
 */
@interface EPViewController ()
{
    UIButton        *_leftButton;
    UIButton        *_rightButton;
    UIBarButtonItem *_leftBarButton;
    UIBarButtonItem *_rightBarButton;
}
@end

@implementation EPViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0/255.f green:122/255.f blue:255/255.f alpha:1]];
//    [self.navigationController.navigationBar setBarTintColor:[UIColor blueColor]];
//    self.navigationController.navigationBar.hidden = YES;
//    [self.view setBackgroundColor:kTableViewBgColor];
    
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if (IS_IOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
    }
#endif
    
    //手势后退
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
    
    //默认为固定的返回按钮
    [self createLeftBarButtonImgName:@"ic_back_white" highlightImgName:@"ic_back"];
    
//    [self setTopNavView];
    
}


//顶部NavView  自定义导航栏
-(void)setTopNavView
{
    _navigationView = [[NavigationView alloc] init];
//    navView.delegate = self;
    _navigationView.titleNameLab.text = self.title;
    [_navigationView.leftButton setImage:[UIImage imageNamed:@"back_press.png"] forState:UIControlStateNormal];
    [_navigationView.leftButton addTarget:self action:@selector(leftBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    _navigationView.leftButton.hidden = NO;
    //    [navView.rightButton setTitle:@"筛选" forState:UIControlStateNormal];
    _navigationView.rightButton.hidden = YES;
    _navigationView.rightButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:_navigationView];
}


#pragma mark - 创建按钮
//纯文字左侧按钮
- (void)createLeftBarButtonTitle:(NSString  *)title
{
    _leftButton = [UINavigationBar customNavCtrlLeftItemWithDefaultBtn:self title:title];
    [_leftButton addTarget:self action:@selector(leftBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}

//纯文字右侧按钮
- (void)createRightBarButtonTitle:(NSString *)title
{
    _rightButton = [UINavigationBar customNavCtrlRightItemWithDefaultBtn:self title:title];
    [_rightButton addTarget:self action:@selector(rightBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}

//纯图片左侧按钮
- (void)createLeftBarButtonImgName:(NSString  *)img highlightImgName:(NSString  *)highImg;
{
    _leftButton = [UINavigationBar customNavCtrlLeftItemWithBgImgName:img highlightBgImgName:highImg targetViewCtrl:self];
    [_leftButton addTarget:self action:@selector(leftBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}

//纯图片右侧按钮
- (void)createRightBarButtonImgName:(NSString  *)img highlightImgName:(NSString  *)highImg;
{
    _rightButton = [UINavigationBar customNavCtrlRightItemWithBgImgName:img highlightBgImgName:highImg targetViewCtrl:self];
    [_rightButton addTarget:self action:@selector(rightBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}

//导航栏右侧双按钮（一个图片，一个文字）
- (void)createRightBarButtonWithBgImgName:(NSString *)bgImgName titleName:(NSString *)titleName
{
    [UINavigationBar customNavCtrlTwoRightItemWithBgImgName:bgImgName titleName:titleName targetViewCtrl:self];
}

//导航栏右侧按钮（一个文字,一个图片）
- (void)createRightBarButtonWithTitleName:(NSString *)titleName bgImgName:(NSString *)bgImgName
{
    [UINavigationBar customNavCtrlRightItemWithTitleName:titleName bgImgName:bgImgName targetViewCtrl:self];

}

//右侧双图片
- (void)createRightBarButtonWithFirstBgImgName:(NSString *)firstBgImgName secondBgImgName:(NSString *)secondBgImgName
{
    [UINavigationBar customNavCtrlTwoRightItemWithFirstBgImgName:firstBgImgName secondBgImgName:secondBgImgName targetViewCtrl:self];
}

#pragma mark - 触发的按钮事件
- (void)leftBarButtonClick:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightBarButtonClick:(UIButton *)btn
{
    
}

- (void)rightBarButtonItemClick:(UIBarButtonItem *)btn
{
    
}

- (void)searchBarButtonItemClick:(UIBarButtonItem *)btn
{
    
}
//导航栏右侧双按钮触发事件（一个图片，一个文字）
- (void)firstRightBarButtonItemClick:(UIBarButtonItem *)btn
{
    
}

- (void)secondRightBarButtonItemClick:(UIBarButtonItem *)btn
{
    
}



@end
